// pages/designer-detail/designer-detail.js
import {textRichFormat} from '../../utils/util'
import {designerType} from '../../utils/const'

const {globalData} = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {}
  },

  requestDetail(id) {
    wx.ajax.post('queryDesignerInfoDetail.action', {id}, true).then(res => {
      let detail = res.result
      detail.head_img = globalData.imageUrl + detail.head_img
      detail.year = (new Date().getFullYear()) - detail.start_year
      detail.year = detail.year < 0 ? 0 : detail.year
      this.setData({
        detail,
        detail_desc: textRichFormat(res.result.detail_desc || '')
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {type, id} = options

    type = type ? type : 6
    
    wx.setNavigationBarTitle({
      title: designerType[type] + "详情",
    })
    this.requestDetail(id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.detail.name,
      path: `/pages/designer-detail/designer-detail?id=${this.detail.id}`,
      imageUrl: this.detail.head_img
    }
  }
})